package com.example.osixaffairssystem.controller;

import com.example.osixaffairssystem.domain.PageBean;
import com.example.osixaffairssystem.domain.Result;
import com.example.osixaffairssystem.domain.model.Schedule;
import com.example.osixaffairssystem.service.ScheduleService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/schedule")
@RequiredArgsConstructor
public class ScheduleController {

    final ScheduleService scheduleService;

    @GetMapping("/list")
    public Result list() {
        log.info("获取课程安排表");
        List<Schedule> list = scheduleService.list();
        return Result.success(list);
    }

    @GetMapping
    public Result listToPage(@RequestParam Integer page,
                             @RequestParam Integer pageSize) {
        log.info("分页查询课程{ page: {}, pageSize: {} }", page, pageSize);
        PageBean<Schedule> list = scheduleService.listToPage(page, pageSize);
        return Result.success(list);
    }

    @PostMapping
    public Result insert(@RequestBody Schedule schedule) {
        log.info("新增课程安排: {}", schedule);
        Integer id = scheduleService.insert(schedule);
        return Result.success(id);
    }

    @PutMapping
    public Result update(@RequestBody Schedule schedule) {
        log.info("更新课程安排: {}", schedule);
        scheduleService.update(schedule);
        return Result.success();
    }

    @DeleteMapping("/{ids}")
    public Result delete(@PathVariable List<Integer> ids) {
        log.info("删除课程安排: {}", ids);
        scheduleService.delete(ids);
        return Result.success();
    }

}
